<?php
class RemindController extends AppController {

	public $name = 'remind';

	function beforeFilter() {
	    parent::beforeFilter(); 
		$this->C_auth->autoRedirect = false; //For override login
	    $this->C_auth->allowedActions = array('index','remindup');

	}
	
	public function remindup() {
        $updsubmit = Request::get_args('updsubmit');
        $deletesubmit = Request::get_args('deletesubmit');
        $searchkey = Request::get_args('searchkey');
        if(is_array($searchkey)){
	        //$rinfo_id=implode(',',$searchkey);
        }else{
	        $rinfo_id=$searchkey;
        }
        if($this->my->locked==1){
	        $this->C_session->destroy();
	        exit("您已经被锁定了");//非法操作
        }
        $user_id = $this->my->id;		
        if($updsubmit){		
			$query  = array();		
			$query['keyid'] = true;
			$safeData['remindinfo'] = array('isread'=>1);				
			$query['set'] = $safeData;	
			$query['conditions'] = array('remindinfo.id'=>$rinfo_id,'remindinfo.user_id'=>$user_id);		
			if(POP::exe('[@@:UM remindinfo][@@:QU save]',$query)) {		
				$this->flash("更新成功！", Router::url('remind/index/'));		        
			} else {	           
				$this->flash("更新失败！", Router::url('remind/index/'));   
			}
        }else if($deletesubmit){
			$query = array('conditions'=>array('remindinfo.user_id' => $user_id,'remindinfo.id' => $rinfo_id));							
			if(POP::exe('[@@:UM remindinfo][@@:QU del]',$query)) {		
				$this->flash("更新成功！", Router::url('remind/index/'));		        
			} else {	           
				$this->flash("更新失败！", Router::url('remind/index/'));   
			}
        }
	
	}
	
	public function index() {
        if($this->my->locked==1){
	        $this->C_session->destroy();
	        exit("您已经被锁定了");//非法操作
        }	
        $type=array(
	        "0"=>"未读",
	        "1"=>"已读",
	        "2"=>"管理员",
        );		
        $user_id = $this->my->id;
		$query = array(
				'fields' => array('remindinfo.*'),
				'conditions' => array('OR'=>array(array('remindinfo.user_id' => $user_id),array('remindinfo.user_id' => 0))),
				'order'=>'remind_time desc'
				);	
		$remind_rs = POP::exe('[@@:UM remindinfo][@@:QU find:all]',$query);		
        $this->set('remind_rs',$remind_rs);	
        $this->set('type',$type);			
        $this->set('user_id',$user_id);		
		
	}

}
?>